/**
 * 
 */
package org.dg.iag.server;

import org.dg.iag.dao.GenericDAO;
import org.dg.iag.entity.Response;
import org.dg.iag.util.ApplicationConstants;
import org.restlet.data.MediaType;
import org.restlet.representation.Representation;
import org.restlet.resource.Get;
import org.restlet.resource.Post;
import org.restlet.resource.ServerResource;

/**
 * @author Alex Gartner
 *
 */
public class StatisticsResource extends ServerResource {
	@Post
	public Response createStatisticsCache() {
		
		GenericDAO<Object, Object> listsGdao		= new GenericDAO<Object, Object>(ApplicationConstants.CREATE_LISTS_CACHE_PATH);
		listsGdao.getElementsAsString();
		
		GenericDAO<Object, Object> gdao		= new GenericDAO<Object, Object>(ApplicationConstants.CREATE_STATS_CACHE_PATH);
		String response	= gdao.getElementsAsString();
		if ( response == null ) {
			return new Response("ok","Updating the stats will take more time. Please check the stats link in about 10 mins.");
		}
		
		return new Response("ok", "ok");
	}
	
	@Get
	public Representation getStatistics() {
		GenericDAO<Object, Object> gdao		= new GenericDAO<Object, Object>(ApplicationConstants.STATS_PATH);
		Representation response						= gdao.getElementsAsRepresentation(MediaType.TEXT_HTML);
		return response;
	}
}
